package com.etc.delivery.service.warehouse.impl;

import com.etc.delivery.dao.warehouse.IWarehouseDao;
import com.etc.delivery.entity.MailType;
import com.etc.delivery.entity.Warehouse;
import com.etc.delivery.entity.Waybill;
import com.etc.delivery.service.warehouse.IWarehouseService;
import com.etc.delivery.utils.MD5Utils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class WareshouseServiceImpl implements IWarehouseService {

    @Resource
    private IWarehouseDao iWarehouseDao;

    @Override
    public List<Warehouse> login(Warehouse warehouse) {


        if (warehouse.getPhone() == null || warehouse.getPassword() == null) {
            return null;
        } else {
            warehouse.setPassword(MD5Utils.getPWD(warehouse.getPassword()));
            return iWarehouseDao.login(warehouse);
        }

    }


    @Override
    public List<Waybill> queryAllByAjax(int waybillNo
            , String mailType
            , String senderName, String senderPhone,
                                        String senderAddress, String recipientName,
                                        String recipientPhone, String recipientAddress,
                                        String mailCost, int status, Integer warehouse_id
    ) {
//        System.out.println(waybill_no);
        return iWarehouseDao.queryAllByAjax(waybillNo, mailType, senderName, senderPhone, senderAddress, recipientName, recipientPhone, recipientAddress
                , mailCost, status, warehouse_id
        );
    }

    @Override
    public boolean addWaybil(int waybillNo) {
        return iWarehouseDao.addWaybill(waybillNo);
    }

    @Override
    public boolean deleteWaybill(int waybill_no) {
        int count = iWarehouseDao.deleteWaybill(waybill_no);
        return count > 0;
    }

    @Override
    public boolean updateByStatus(int waybill_no) {
        return iWarehouseDao.updateByStatus(waybill_no);
    }

    @Override
    public List<Waybill> queryAllBywaybill_no(int waybill_no, int warehouse_id) {
        return iWarehouseDao.queryAllBywaybill_no(waybill_no, warehouse_id);
    }


    @Override
    public boolean updateWaybill(int mail_type, String sender_name, String sender_phone, String sender_address, String recipient_name, String recipient_phone, String recipient_address, int mail_cost, int waybill_no) {
        return iWarehouseDao.updateWaybill(mail_type, sender_name, sender_phone, sender_address, recipient_name, recipient_phone, recipient_address, mail_cost, waybill_no
        );
    }

    @Override
    public List<MailType> queryMailName() {
        return iWarehouseDao.queryMailName();
    }

}
